<?php
class Relations_Model extends CI_Model {
	
	public function addRelation($data) {
		$required = array ('HOSTID', 'FRIENDID' );
		if (! $this->_required ( $required, $data ))
			return false;
		
		$data ['CREATETIME'] = date ( 'Y-m-d H:i:s' );
		
		$this->load->database ();
		$this->db->insert ( 'RELATIONS', $data );
		$this->db->close ();
	}
	
	public function getRelation($relation_id) {
		if (! is_int ( $relation_id ))
			return false;
		
		$this->load->database ();
		
		$this->db->where ( 'RELATIONID', $relation_id );
		$this->db->from ( 'RELATIONS' );
		$query = $this->db->get ();
		
		$this->db->close ();
		
		return $query->result_array ();
	}
	
	public function getRelations($user_id) {
		if (! is_int ( $user_id ))
			return false;
		
		$this->load->database ();
		
		$this->db->where ( 'USERID', $user_id );
		$this->db->from ( 'RELATIONS' );
		$query = $this->db->get ();
		
		$this->db->close ();
		
		return $query->result_array ();
	}
	
	public function deleteRelation($relation_id) {
		if (! is_int ( $relation_id ))
			return false;
		
		$this->load->database ();
		$this->db->delete ( 'RELATIONS', array ('RELATIONID' => $relation_id ) );
		$this->db->close ();
		
		return true;
	}
}